| Conditions | 3 |
| Paths | 3 |
| Total Lines | 24 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 1 | Features | 0 |
| 1 | import optionsFromStrings from "./optionsFromStrings.js"; |
||
| 3 | function getOptionsFromElement(element){ |
||
| 4 | var options = {}; |
||
| 5 | |||
| 6 | var attributes = element.attributes; |
||
| 7 | for(var i = 0; i < attributes.length; i++){ |
||
| 8 | var name = attributes[i].name; |
||
| 9 | var value = attributes[i].value; |
||
| 10 | |||
| 11 | var match = name.match(/(jsbarcode|data)-([A-Za-z0-9-]+)/i); |
||
| 12 | if(match){ |
||
| 13 | var property = match[2]; |
||
| 14 | |||
| 15 | // Transforms foo-bar to fooBar |
||
| 16 | property = property.replace(/-[a-zA-Z]/, (val) => val[1].toUpperCase()); |
||
| 17 | |||
| 18 | options[property] = value; |
||
| 19 | } |
||
| 20 | } |
||
| 21 | |||
| 22 | // Since all atributes are string they need to be converted to integers |
||
| 23 | options = optionsFromStrings(options); |
||
| 24 | |||
| 25 | return options; |
||
| 26 | } |
||
| 27 | |||
| 29 |